package com.gwm.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gwm.common.utils.BeanHelper;
import com.gwm.user.dto.UserAddressDTO;
import com.gwm.user.entity.TbUserAddress;
import com.gwm.user.mapper.TbUserAddressMapper;

import com.gwm.user.service.TbUserAddressService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 用户收货地址表 服务实现类
 * </p>
 *
 * @author heima
 * @since 2020-12-01
 */
@Service
public class TbUserAddressServiceImpl extends ServiceImpl<TbUserAddressMapper, TbUserAddress> implements TbUserAddressService {
    @Override
    public UserAddressDTO findByUserIdAndId(Long userId, Long id) {
        QueryWrapper<TbUserAddress> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(TbUserAddress::getId,id);
        queryWrapper.lambda().eq(TbUserAddress::getUserId,userId);
        TbUserAddress tbUserAddress = this.getOne(queryWrapper);
        return BeanHelper.copyProperties(tbUserAddress,UserAddressDTO.class);
    }

    @Override
    public List<UserAddressDTO> findByUserId(String userId) {

        QueryWrapper<TbUserAddress> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(TbUserAddress::getUserId,userId);
        List<TbUserAddress> list = this.list(queryWrapper);
        return BeanHelper.copyWithCollection(list,UserAddressDTO.class);
    }

}
